<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								路由url：<input type="text" name="url"/>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:gatewayConfig:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="system:gatewayConfig:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:gatewayConfig:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:gatewayConfig:export">
						<i class="fa fa-download"></i> 导出
				 </a>
                <a class="btn btn-info" onclick="refreshRoute()" shiro:hasPermission="system:gatewayConfig:refresh">
                    <i class="fa fa-refresh"></i> 刷新路由
                </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:gatewayConfig:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:gatewayConfig:remove')}]];
        var prefix = ctx + "system/gatewayConfig";
        //刷新路由
        var refreshRoute=function(){
            $.modal.confirm("确认要刷新路由吗?", function() {
                var url = prefix+"/refresh";
                $.operate.submit(url, "get", "json", "");
            });
        };
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "网关路由配置",
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'serviceId', 
					title : '路由唯一id',
					visible: false
				},
				{
					field : 'url', 
					title : '路由url',
				},
				{
					field : 'suffixPath', 
					title : '路由后缀Path，紧跟url',
				},
				{
					field : 'createTime', 
					title : '创建时间',
					sortable: true
				},
				{
					field : 'updateTime', 
					title : '修改时间',
					sortable: true
				},
				{
					field : 'state', 
					title : '状态',
                    formatter: function(value, row, index) {
                        return statusTools(row);
                    }
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.serviceId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        /*route状态启停*/
        function statusTools(row) {
            if (row.state == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.serviceId + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.serviceId + '\')"></i> ';
            }
        }

        /* route启用 */
        function enable(id) {
            $.modal.confirm("确认要启用该路由吗？", function() {
                $.operate.post(prefix + "/changeState", { "serviceId": id, "state": 1 });
            })
        }

        /* route停用 */
        function disable(id) {
            $.modal.confirm("确认要停用该路由吗？", function() {
                $.operate.post(prefix + "/changeState", { "serviceId": id, "state": 0 });
            })
        }
    </script>
</body>
</html>